﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

using System;
using System.Linq;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using ScrumTable.BL.DM.DataManagement;
using ScrumTable.Common.Collections;
using ScrumTable.Common.Data;
using ScrumTable.DL.Data.Local.Test;
using ScrumTable.DL.Data.Schema.ScrumTableV1;

#endregion

namespace ScrumTable.BL.DM.Test.DataManagement
{
    /// <summary>
    /// This is the test class for Member class.
    /// </summary>
    [TestClass]
    public class ReportTest : DomainBaseTest<Report, ReportSchema>
    {
        #region Declarations
        //--------------------------------------------------------------------
        // Declarations
        //--------------------------------------------------------------------

        #endregion

        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        /// <summary>
        /// Gets the default instance to test.
        /// </summary>
        protected override Report ToTest
        {
            get { return Context.Projects[Resources.Project1Id].Reports[Resources.Report1Id]; }
        }

        #endregion

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------

        /// <summary>
        /// Creates a new ReportTest instance.
        /// </summary>
        public ReportTest()
        {
        }

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------

        /// <summary>
        /// Use TestInitialize to run code before running each test .
        /// </summary>
        [TestInitialize]
        public override void TestInitialize()
        {
            base.TestInitialize();
        }

        /// <summary>
        /// Use TestCleanup to run code after each test has run.
        /// </summary>
        [TestCleanup]
        public override void TestCleanup()
        {
            base.TestCleanup();
        }

        [TestMethod]
        public override void TestParent()
        {
            Assert.IsNotNull(ToTest.Parent);
        }
        
        [TestMethod]
        public void TestPath()
        {
            Assert.AreEqual("TestReport1", ToTest.Path);
        }

        [TestMethod]
        public void TestFullPath()
        {
            Assert.AreEqual(new Uri("report1.jpg", UriKind.RelativeOrAbsolute), ToTest.FullPath);
        }

        [TestMethod]
        public void TestToPostCommandArguments()
        {
            Pair<string, string>[] pairs = new[]
                                               {
                                                   new Pair<string, string>("key1", "value&"),
                                                   new Pair<string, string>("key2", "value")
                                               };
            string postCmdArgs = ToTest.ToPostCommandArguments(pairs);

            Assert.IsNotNull(postCmdArgs);
            Assert.AreEqual("key1=value%26&key2=value", postCmdArgs);
        }

        [TestMethod]
        public void TestFieldMeta()
        {
            Assert.IsNotNull(ToTest.FieldMeta);
            Assert.IsTrue(ToTest.FieldMeta.Count > 0);
            Assert.AreEqual("Name", ToTest.FieldMeta.First().Name);
            Assert.AreEqual("Name", ToTest.FieldMeta.First().DisplayName);

            NamedValue defaultValue = ToTest.FieldMeta.First().AllowedValuesTyped.First();
            Assert.AreEqual(defaultValue, ToTest.FieldMeta.First().DefaultValue);

            Assert.AreEqual(typeof(string), ToTest.FieldMeta.First().FieldType);
            Assert.AreEqual(DataType.String, ToTest.FieldMeta.First().FieldTypeFormat);
            Assert.AreEqual("String", ToTest.FieldMeta.First().FieldTypeName);
        }

        /// <summary>
        /// Gets the default schema of the instance to test.
        /// </summary>
        /// <param name="schema">Specifies the parent schema instance.</param>
        /// <returns>Returns the retrieved schema instance.</returns>
        protected override ReportSchema GetSchema(ScrumTableV1Schema schema)
        {
            return schema.ReportSchema;
        }

        #endregion

        #region Events
        //--------------------------------------------------------------------
        // Events
        //--------------------------------------------------------------------

        #endregion
    }
}
